import request from "../../../utils/request"
import type {
  ResponseSpuData,
  ResponseSpuAttrData,
  AllTrademark,
  SpuData,
} from "./type"

enum API {
  PAGESPU_URL = "/admin/product/",
  SPU_ATTR_URL = "/admin/product/baseSaleAttrList",
  ALL_PRODUCT_URL = "/admin/product/baseTrademark/getTrademarkList",
  SPU_ADD_URL = "/admin/product/saveSpuInfo",
  SPU_UPDATE_URL = "/admin/product/updateSpuInfo",
}

export const getSpuPage = (
  pageNo: number,
  pageSize: number,
  c3Id: number | string,
) =>
  request.get<any, ResponseSpuData>(
    API.PAGESPU_URL + `${pageNo}/${pageSize}?category3Id=${c3Id}`,
  )

export const getSpuAttr = () =>
  request.get<any, ResponseSpuAttrData>(API.SPU_ATTR_URL)

export const getAllProduct = () =>
  request.get<any, AllTrademark>(API.ALL_PRODUCT_URL)

export const spuAddOrUpdate = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.SPU_ADD_URL, data)
  } else {
    return request.post<any, any>(API.SPU_UPDATE_URL, data)
  }
}
